{% extends "master.html" %}
{% block content_header_title%}插件{% end %}
{% block content_header_breadcrumb%}{% end %}
{% block content_body%}
<div class="box box-primary">
    <div class="box-header with-border">
        <h3 class="box-title">插件列表</h3>

        <div class="box-tools pull-right">
            <span class="text-muted">激活或者卸载插件需要重加载，否则在服务器重启后生效.</span>
            <a class="btn" onclick="bo_plugins_reload(this);">
                <i class="fa fa-repeat"></i> 重加载
            </a>
        </div>
    </div>
    <!-- /.box-header -->
    <div class="box-body">
        <ul class="products-list product-list-in-box">
            {% for plugin in plugins %}
            {% set css_cls = "bg-green" %}
            {% set enable_text = "激活" %}
            {% if plugin['status'] %}
            {% set css_cls = "bg-red" %}
            {% set enable_text = "卸载" %}
            {% end %}
            <li class="item">
                <a href="javascript:void(0)" class="product-title">{{plugin["name"]}} (v{{plugin["version"]}})
                </a>
                {% if not plugin["alway"] %}
                <a class="label {{css_cls}} pull-right" data-status="{{plugin['status']}}" data-id="{{plugin['id']}}"
                   onclick="bo_change_plugin_status(this);">{{enable_text}}</a>
                {% end %}
                <span class="product-description">
                          {{plugin["description"]}}
                        </span>
                {% if plugin["author"] %}
                <a href="{{plugin['author_uri']}}">作者: {{plugin["author"]}}</a>
                {% end %}
                {% if plugin["uri"] %}
                <a href="{{plugin['uri']}}">插件网站</a>
                {% end %}
            </li>
            <!-- /.item -->
            {% end %}
        </ul>
    </div>
    <!-- /.box-body -->
    <div class="box-footer text-center">

    </div>
    <!-- /.box-footer -->
</div>
{% end %}
{% block footer%}
<script type="text/javascript">
    function bo_plugins_reload(elm){
        $(elm).toggleClass("disabled");
        $.post("{{reverse_url('plugins_reload')}}", bo_xsrf({}), function(rsp){
            document.location.reload();
        }, "json");
    }
    function bo_change_plugin_status(elm){
        var self = $(elm);
        var id = self.data("id");
        var status = self.data("status");
        $.post("{{api('bo_change_plugin_status')}}", bo_xsrf({id:id,status:status}), function(rsp){
            if(rsp.success){
                if(status=="True"){
                    self.removeClass('bg-red');
                    self.addClass('bg-green');
                    self.html('激活');
                    self.data("status", "False");
                }else{
                    self.removeClass('bg-green');
                    self.addClass('bg-red');
                    self.html('卸载');
                    self.data("status", "True");
                }
            }
        }, "json");
    }

</script>
{% end %}